﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Igpay_atinlay_anlstorlray
{
    public enum Translation
    {
        EnglishToPLatin,
        PLatinToEnglish
    }
    static class Translator
    {
        const string Vowels = "aeiouy";
        const string Punctuators = ".!?,";
        public class Symblol
        {
            public string Character;
            public int Location;
            public Symblol(int Location, string Character)
            {
                this.Location = Location;
                this.Character = Character;
            }
        }
        class sentence
        {
            public List<string> words = new List<string>();
            public List<Symblol> symbols = new List<Symblol>();
            public string Punctation;


            //Override the ToString Method
            //This returns the full sentence including the Proper Quotations
            public override string ToString()
            {
                //Stringbuilder that will be the final Full Sentence
                StringBuilder FullSentence = new StringBuilder();

                //Number of words and the number of symbols
                //Keeping count of how many there are, so if you place symbols like commas and other non letter characters
                //Then they can be placed back into their proper positions
                int WordCount = words.Count;
                int SymbolCount = symbols.Count;
                int[] SymbolPositions = new int[SymbolCount];

                int ArrayPosition = 0;

                //Creates the array that knows where all the symbols will be placed in relation to the preceding word
                foreach (Symblol s in symbols)
                {
                    SymbolPositions[ArrayPosition] = s.Location;
                    ArrayPosition++;
                }
                ArrayPosition = 0;
                for (int i = 0; i < WordCount; i++)
                {
                    if (i == 0)
                    {
                        if (words[i].Length > 1)
                            words[i] = words[i].Substring(0, 1).ToUpper() + words[i].Substring(1);
                        else
                            words[i] = words[i].ToUpper();
                    }
                    FullSentence.Append(words[i]);
                    if (SymbolCount != 0 && ArrayPosition != SymbolCount)
                    {
                        if (SymbolPositions[ArrayPosition] == i)
                            FullSentence.Append(symbols[ArrayPosition].Location);
                    }
                    if (i != WordCount - 1)
                        FullSentence.Append(' ');
                }
                if (!string.IsNullOrEmpty(Punctation))
                    FullSentence.Append(Punctation);
                return FullSentence.ToString();
            }
            public void Translate(Translation trans)
            {
                for (int i = 0; i < words.Count; i++)
                {
                    switch (trans)
                    {
                        case Translation.EnglishToPLatin:
                            words[i] = TrannslatToPigLatin(words[i]);
                            break;
                        case Translation.PLatinToEnglish:
                            break;
                    }
                }
            }
        }
        static string Translate(string input)
        {
            StringBuilder Output = new StringBuilder();
            RipoutSentences(input);


            
            return Output.ToString();
        }
        static string TrannslatToPigLatin(string input)
        {
            
            int VowelLocation = input.IndexOfAny(Vowels.ToCharArray());
            if (VowelLocation == 0)
            {
                input = input.Insert(input.Length, "-way");
            }
            else
            {
                input = input.Substring(VowelLocation) + "-" + input.Substring(0, VowelLocation) + "ay";
            }
            return input;
        }
        static string TranslateToEnglish(string input)
        {
            if (input.Contains('-'))
            {
                string ending;
                string begining;
                ending = input.Substring(0, input.IndexOf('-'));
                begining = input.Substring(input.IndexOf('-') + 1);
                begining = begining.Remove(begining.IndexOf("ay"));
                input = begining.ToLower() + ending.ToLower();
            }
            else if(input.Contains("way"))
            {
                input = input.Remove(input.IndexOf("way", (input.Length ))-1);
            }
            return input;
        }
        //rips out the individual sentences to convert them into pig latin
        static List<string> RipoutSentences(string input)
        {
            List<string> Output = new List<string>();

            return Output;
        }
        static List<string> RipoutWords(List<string> Sentences)
        {
            List<string> Output = new List<string>();

            return Output;
        }
    }
}
